package userHelp

import (
	myredis "common/redis"
	"time"
)

type TblProxyBase struct {
	Uid               string  `json:"uid" cbor:"uid" db:"uid"`
	ParentID          string  `json:"parent_id" cbor:"parent_id" db:"parent_id"` //lv1
	ParentName        string  `json:"parent_name" cbor:"parent_name" db:"parent_name"`
	GrandId           string  `json:"grand_id" cbor:"grand_id" db:"grand_id"` //lv2
	GrandName         string  `json:"grand_name" cbor:"grand_name" db:"grand_name"`
	GreatGrandId      string  `json:"great_grand_id" cbor:"great_grand_id" db:"great_grand_id"` //lv3
	GreatGrandName    string  `json:"great_grand_name" cbor:"great_grand_name" db:"great_grand_name"`
	DonateToParent    float64 `json:"DonateToParent" cbor:"DonateToParent" db:"DonateToParent"`
	FirstDepositMount float64 `json:"first_deposit_mount" cbor:"first_deposit_mount" db:"first_deposit_mount"`
	CreatedTime       string  `json:"created_at" cbor:"created_at" db:"created_at"`
	DonateTime        string  `json:"DonateTime" cbor:"DonateTime" db:"DonateTime"`
	UnbindParentId    string  `json:"UnbindParentId" cbor:"UnbindParentId" db:"UnbindParentId"`
	RegIP             string  `json:"regIP" cbor:"regIP" db:"regIP"`
}

var g_tbl_proxy_base = "tbl_proxy_base:"

func SetProxyParentId(uid string, ParentID string) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValue(uid, g_tbl_proxy_base+"parent_id", ParentID)
}

func SetProxyParentName(uid string, ParentName string) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValue(uid, g_tbl_proxy_base+"parent_name", ParentName)
}

func GetUnbindParentId(uid string) string {
	LoadUserToRedis(uid)
	UnbindParentId := myredis.GetUserFieldString(uid, g_tbl_proxy_base+"UnbindParentId")
	if UnbindParentId == "" {
		UnbindParentId = "0"
	}

	return UnbindParentId
}

func GetProxyParentId(uid string) string {
	LoadUserToRedis(uid)
	ParentID := myredis.GetUserFieldString(uid, g_tbl_proxy_base+"parent_id")
	if ParentID == "" {
		ParentID = "0"
	}

	return ParentID
}

func GetProxyParentName(uid string) string {
	LoadUserToRedis(uid)
	ParentName := myredis.GetUserFieldString(uid, g_tbl_proxy_base+"parent_name")
	return ParentName
}

func GetProxyGrandId(uid string) string {
	LoadUserToRedis(uid)
	GrandId := myredis.GetUserFieldString(uid, g_tbl_proxy_base+"grand_id")
	if GrandId == "" {
		GrandId = "0"
	}

	return GrandId
}

func GetProxyGrandName(uid string) string {
	LoadUserToRedis(uid)
	GrandName := myredis.GetUserFieldString(uid, g_tbl_proxy_base+"grand_name")
	return GrandName
}

func GetRegIp(uid string) string {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldString(uid, g_tbl_proxy_base+"regIP")
}

func SetFirstDepositAmount(uid string, FirstDepositAmount float64) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValueByFloat64(uid, g_tbl_proxy_base+"first_deposit_mount", FirstDepositAmount)
}

func SetDonateAmountToParent(uid string, DonateAmount float64) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValueByFloat64(uid, g_tbl_proxy_base+"DonateToParent", DonateAmount)
	myredis.SetUserFieldValue(uid, g_tbl_proxy_base+"DonateTime", time.Now().Format(time.DateTime))
}

func AddDonateAmountToParent(uid string, DonateAmount float64) {
	LoadUserToRedis(uid)
	myredis.AddUserFieldValueByFloat64(uid, g_tbl_proxy_base+"DonateToParent", DonateAmount)
	myredis.SetUserFieldValue(uid, g_tbl_proxy_base+"DonateTime", time.Now().Format(time.DateTime))
}

func GetFirstDepositAmount(uid string) float64 {
	LoadUserToRedis(uid)
	return myredis.GetUserFieldFloat64(uid, g_tbl_proxy_base+"first_deposit_mount")
}

func SetProxyGrandId(uid string, GrandId string) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValue(uid, g_tbl_proxy_base+"grand_id", GrandId)
}

func SetProxyGrandName(uid string, GrandName string) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValue(uid, g_tbl_proxy_base+"grand_name", GrandName)
}

func SetProxyGreatGrandId(uid string, GreatGrandId string) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValue(uid, g_tbl_proxy_base+"great_grand_id", GreatGrandId)
}

func SetProxyGreatGrandName(uid string, GreatGrandName string) {
	LoadUserToRedis(uid)
	myredis.SetUserFieldValue(uid, g_tbl_proxy_base+"great_grand_name", GreatGrandName)
}

func GetProxyGreatGrandId(uid string) string {
	LoadUserToRedis(uid)
	GrandId := myredis.GetUserFieldString(uid, g_tbl_proxy_base+"great_grand_id")
	if GrandId == "" {
		GrandId = "0"
	}

	return GrandId
}
